<?php
namespace app\api\controller\v1;
use think\facade\Request;
class Coupons extends Base{



	//每个店铺的优惠卷
    public function select(){
         model('coupons')->select();
      
    }

    //领取优惠卷
    public function takeCoupons(){
    	$data = Request::post();
    	$token = Request()->header('Token');

        if(isset($data['uid'])&&!empty($data['uid'])&&$data['uid'] != 'undefined' && !empty($token)){
            $uid = $data['uid'];
            $status = $this->verifyToken($uid,$token);
        
              if($token && $status){
               model('coupons')->take($data);
        }
    }else{
            return_json(40001,'token过期了',40001);
                    }
       
    }


    public function detail(){
        $id = Request::param('id');
        model('coupons')->det($id);
    }

    //后台操作优惠卷
    public function sel(){
         $pagesize = Request::param('pagesize');
         $pagenum = Request::param('pagenum');
          model('coupons')->sel($pagesize,$pagenum);
    }

    public function edit(){
        $id = Request::param('id');
        $data = Request::post();

          $validate = new \app\api\validate\Coupon;
        if (!$validate->check($data)) {
            return_json(400,'失败',$validate->getError());
        }else{

            model('coupons')->edit($id,$data);
        }
        
    }

    public function add(){
         $data = Request::post();
           $validate = new \app\api\validate\Coupon;
        if (!$validate->check($data)) {
            return_json(400,'失败',$validate->getError());
        }else{

            model('coupons')->add($data);
        }
    }


    public function delete(){
      $id = Request::param('id');
      model('coupons')->del($id);
    }

      public function delAll(){
          $ids = Request::param('ids');
        model('coupons')->delAll($ids);
          
  
    }
}

?>